package club.sanmubird.springbootrabbitmq.rabbitmq.demo;

import club.sanmubird.springbootrabbitmq.rabbitmq.config.DemoMqConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.UUID;


/**
 * @author Sam
 */
@Slf4j
@Component
public class DemoProducer {


	@Autowired
	@Qualifier(value = "demoRabbitTemplate")
	private RabbitTemplate rabbitTemplate;


	public void sendMsg(String message) {
		CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
		rabbitTemplate.convertAndSend(DemoMqConfig.EXCHANGE, DemoMqConfig.SEND_ROUTING_KEY, message, correlationId);
	}

}
